Skip to content

feat(rates): use XRC as primary ICP/USD exchange rate source#365

Merged
yhabib merged 8 commits intomainfrom
feat/xrc-source
Apr 10, 2026
Merged

feat(rates): use XRC as primary ICP/USD exchange rate source#365
yhabib merged 8 commits intomainfrom
feat/xrc-source

Conversation

@yhabib
Copy link
Copy Markdown
Collaborator

@yhabib yhabib commented Apr 1, 2026

Motivation

The ICP/USD exchange rate was previously obtained from external DEX APIs (IcpSwap as the primary source and KongSwap as a fallback). The backend canister now queries the XRC (Exchange Rate Canister) directly and caches the result, allowing us to use it as the primary source and display the 24-hour price change.

Screenshot 2026-04-01 at 18 53 02

Changes

  • Removed KongSwap as a price provider (including hooks, types, fixtures, end-to-end stubs, tests, and environment configuration).
  • Added the useExchangeRate hook, which calls get_icp_to_usd_exchange_rate on the backend canister.
  • Updated useTickerPrices to use the backend canister as the primary source, with IcpSwap as a fallback.
  • Modified useTvlValue to utilize the unified useTickerPrices hook instead of calling IcpSwap directly.
  • Added an optional previousUsd field to the TokenPrices type, populated from the backend's one_day_ago rate.
  • Enhanced IcpPriceCard to display the 24-hour price change with a directional triangle indicator.

@yhabib yhabib requested a review from Copilot April 1, 2026 16:53
@yhabib yhabib changed the title feat(frontend): use XRC as primary ICP/USD exchange rate source feat(rates): use XRC as primary ICP/USD exchange rate source Apr 1, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

📊 Build Bundle Stats

The latest build generated the following assets:

dist/index.html                                           1.92 kB │ gzip:   0.68 kB
dist/assets/index-D5Qot_eu.css                          129.73 kB │ gzip:  20.46 kB
dist/assets/neuron-CW_joJs1.js                            0.08 kB │ gzip:   0.09 kB
dist/assets/externalServices-B9hWFV-7.js                  0.21 kB │ gzip:   0.17 kB
dist/assets/useTvlValue-DS1dsq-3.js                       0.58 kB │ gzip:   0.39 kB
dist/assets/Spinner-DSIlSj14.js                           0.58 kB │ gzip:   0.40 kB
dist/assets/service-Co7lVj4r.js                           0.60 kB │ gzip:   0.39 kB
dist/assets/useHideBalances-5OO6lHFZ.js                   0.61 kB │ gzip:   0.40 kB
dist/assets/numbers-BIg8C6a4.js                           0.61 kB │ gzip:   0.37 kB
dist/assets/PageHeader-Cr3cEbbs.js                        0.75 kB │ gzip:   0.44 kB
dist/assets/Separator-Cv0UTCrv.js                         0.77 kB │ gzip:   0.46 kB
dist/assets/CertifiedBadge-CcJp7_Gd.js                    0.80 kB │ gzip:   0.48 kB
dist/assets/useIcpIndex-BW7LzOko.js                       1.08 kB │ gzip:   0.63 kB
dist/assets/addressBook-D74kgK3t.js                       1.09 kB │ gzip:   0.70 kB
dist/assets/Switch-CLrwkVVg.js                            1.65 kB │ gzip:   0.82 kB
dist/assets/CopyButton-D0frRiPo.js                        1.86 kB │ gzip:   0.95 kB
dist/assets/AnimatedNumber-B5yN7hOo.js                    1.86 kB │ gzip:   1.04 kB
dist/assets/useGovernanceAppCanister-C0YNHo1T.js          1.92 kB │ gzip:   0.97 kB
dist/assets/useInfiniteQueryThenUpdateCall-CBVmUqiv.js    1.93 kB │ gzip:   0.96 kB
dist/assets/ToggleGroup-XMkUKjjg.js                       3.05 kB │ gzip:   1.33 kB
dist/assets/useTickerPrices-C_ym2ys-.js                   3.16 kB │ gzip:   1.50 kB
dist/assets/_auth-CcExP_0u.js                             4.19 kB │ gzip:   2.01 kB
dist/assets/AmountInput-BSS26r67.js                       6.37 kB │ gzip:   2.91 kB
dist/assets/useSpamFilterCanister-BoYarDGy.js             7.20 kB │ gzip:   3.24 kB
dist/assets/QueryStates-90vt5yQv.js                       7.94 kB │ gzip:   2.27 kB
dist/assets/index-CPOpPMLo.js                             8.72 kB │ gzip:   3.37 kB
dist/assets/Input-CtKtNAcS.js                             9.40 kB │ gzip:   3.35 kB
dist/assets/TopicFollowingAccordion-BZ7KFPYr.js          10.05 kB │ gzip:   4.00 kB
dist/assets/types-QMoKSnZg.js                            10.70 kB │ gzip:   4.56 kB
dist/assets/index-BbOM5r89.js                            14.43 kB │ gzip:   4.58 kB
dist/assets/index-McJIXRW3.js                            23.48 kB │ gzip:   8.05 kB
dist/assets/DepositICPModal-reIY44SG.js                  39.67 kB │ gzip:  13.88 kB
dist/assets/index-DXlIBnT_.js                            40.94 kB │ gzip:  11.78 kB
dist/assets/index-CmeVYogN.js                            49.73 kB │ gzip:  14.99 kB
dist/assets/index-BODenVuD.js                            67.11 kB │ gzip:  20.64 kB
dist/assets/vendor-md-KelhpvMd.js                        89.32 kB │ gzip:  25.51 kB
dist/assets/index-DcS7swH1.js                           120.79 kB │ gzip:  38.94 kB
dist/assets/index-BzejyDCN.js                           121.98 kB │ gzip:  34.51 kB
dist/assets/vendor-tanstack-DNwsJOPx.js                 126.65 kB │ gzip:  39.34 kB
dist/assets/vendor-core-react-By6K7kM9.js               193.24 kB │ gzip:  60.69 kB
dist/assets/vendor-recharts-L2KVWzi1.js                 228.10 kB │ gzip:  65.92 kB
dist/assets/vendor-icp-BoXv3tub.js                      402.37 kB │ gzip: 100.05 kB
dist/assets/vendor-libs-C4Nvvb3f.js                     541.61 kB │ gzip: 179.11 kB

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the frontend price-fetching flow to use the backend canister’s XRC-sourced ICP/USD exchange rate as the primary source (including 24h change), while removing KongSwap as a provider and keeping IcpSwap as a fallback.

Changes:

  • Removed KongSwap integration across typings, hooks, fixtures, e2e stubs, tests, and env config.
  • Added useExchangeRate to fetch get_icp_to_usd_exchange_rate from the backend canister and parse current + one_day_ago.
  • Updated UI and consumers (useTickerPrices, useTvlValue, IcpPriceCard) to use the new unified flow and display 24h change.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/governance-app-frontend/tests/fixtures/kongSwap.ts Removes KongSwap fixtures used in unit/e2e tests.
src/governance-app-frontend/tests/e2e/utils/app.ts Updates e2e bootstrap stubbing (removes KongSwap stub).
src/governance-app-frontend/tests/e2e/stubs/kongSwap.ts Removes KongSwap network stub for Playwright.
src/governance-app-frontend/src/i18n/en/home.json Adds a new label for the 24h change indicator.
src/governance-app-frontend/src/features/dashboard/components/IcpPriceCard.tsx Displays ICP 24h change based on previousUsd from backend.
src/governance-app-frontend/src/common/utils/query.ts Removes KongSwap query key and adds backend exchange-rate query key.
src/governance-app-frontend/src/common/typings/tokenPrices.ts Extends TokenPrices with optional previousUsd.
src/governance-app-frontend/src/common/typings/kongSwap.ts Removes KongSwap response typings.
src/governance-app-frontend/src/common/hooks/useTvlValue.ts Switches TVL calculation to use unified useTickerPrices.
src/governance-app-frontend/src/common/hooks/tickers/useTickerPrices.ts Makes backend exchange rate primary; IcpSwap becomes fallback.
src/governance-app-frontend/src/common/hooks/tickers/useKongSwapPrices.ts Removes KongSwap price hook and parsing logic.
src/governance-app-frontend/src/common/hooks/tickers/useKongSwapPrices.test.tsx Removes unit tests for KongSwap parsing.
src/governance-app-frontend/src/common/hooks/tickers/useExchangeRate.ts Adds backend-driven exchange rate hook + parser (with previousUsd).
src/governance-app-frontend/src/common/hooks/tickers/useExchangeRate.test.tsx Adds unit tests for exchange-rate response parsing.
src/governance-app-frontend/src/common/hooks/tickers/index.ts Exports new exchange-rate hook; removes KongSwap exports.
src/governance-app-frontend/src/common/constants/externalServices.ts Removes KongSwap URL env var reference.
scripts/config.sh Removes EXTRA_KONG_SWAP_URL from generated config.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/governance-app-frontend/src/common/hooks/tickers/useExchangeRate.ts Outdated
Comment thread src/governance-app-frontend/src/common/hooks/tickers/useExchangeRate.ts Outdated
Comment thread src/governance-app-frontend/tests/e2e/utils/app.ts
@yhabib yhabib marked this pull request as ready for review April 2, 2026 11:27
@yhabib yhabib requested a review from a team as a code owner April 2, 2026 11:27
@yhabib yhabib force-pushed the feat/xrc-source branch 3 times, most recently from 2ac57da to d82812c Compare April 8, 2026 13:05
Comment thread src/governance-app-frontend/src/common/hooks/tickers/useTickerPrices.ts Outdated
yhabib added 8 commits April 10, 2026 14:55
…:22]: refactor(frontend): remove KongSwap price provider

IcpSwap is now the sole exchange rate provider, simplifying
the ticker price fetching logic before introducing the backend
canister as the primary source.
…:22]: feat(frontend): use backend canister as primary ICP/USD exchange rate source

Call get_icp_to_usd_exchange_rate from the backend canister which
fetches rates from the XRC canister and caches them. IcpSwap is
kept as a fallback if the backend call fails.
…fix prettier and unit test failures

- Format IcpPriceCard.tsx (prettier)
- Add vitest alias + mock stub for governance-app-backend declarations,
  which are DFX-generated and not committed to git
@yhabib yhabib added this pull request to the merge queue Apr 10, 2026
Merged via the queue into main with commit 5c2a687 Apr 10, 2026
11 checks passed
@yhabib yhabib deleted the feat/xrc-source branch April 10, 2026 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants